﻿using OneWeb.DbContexts;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace OneWeb.Repository
{
    public class Repository<T> where T : class
    {
        public Repository()
        {
            context = new OneDataContext(); 
            DbSet = context.Set<T>();
        }

        public Repository(OneDataContext context)
        {
            this.context = context;
        }

        private OneDataContext context;

        protected DbSet<T> DbSet
        {
            get;
            set;
        }

       public List<T> GetAll()
        {
            return DbSet.ToList();
        }

        public T Get (int id)
        {
            return DbSet.Find(id);
        }

        public void Add(T entity)
        {
            DbSet.Add(entity);
        }
        

        public void SaveChanges()
        {
            context.SaveChanges();
        }
    }
}